package cn.lavender.unit.service;

import cn.lavender.unit.dao.UserDao;
import cn.lavender.unit.entity.User;
import cn.lavender.unit.utils.ConfigUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {

    private UserDao userDao;

    public UserService() {
    }

    /**
     * 构造器注入时，@Autowired可写可不写
     */
    @Autowired
    public UserService(UserDao userDao) {
        this.userDao = userDao;
    }

    /**
     * 1：普通对象测试用例
     */
    public int getTotalUser() {
        return userDao.getTotal();
    }

    public void saveUser(User user) {
        userDao.saveUser(user);
    }

    /**
     * 2：局部变量测试用例
     */
    public int getTotalUserByNewDao() {
        UserDao userDao = new UserDao();
        return userDao.getTotal();
    }

    /**
     * 3：静态方法测试用例
     */
    public String getDbIp() {
        return ConfigUtils.getDbIp();
    }

    /**
     * 4：final修饰的测试用例
     * 跟普通类、方法的mock
     */
    public int getFinalTotal() {
        return userDao.getFinalTotal();
    }

    /**
     * 5：private修饰的测试用例
     */
    private boolean login() {
        return true;
    }

}
